let candidates = [2, 3, 5], target = 8, result = []

function backtrack(start, path, remain) {
    if (remain < 0) {
        return
    } else if (remain == 0) {
        result.push([...path])
    }
    else {
        for (let i = start; i < candidates.length; i++) {
            path.push(candidates[i])
            backtrack(i, path, remain - candidates[i])
            path.pop()
        }
    }
}

backtrack(0, [], target)

console.log(result)